package com.bobo.web.provider.controller.nio_redis_zookeeper.bio;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.Scanner;

public class Socket_01Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 8080);
        DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
        DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());
        Scanner scanner = new Scanner(System.in);
        System.out.println("wait client in");
        String readLine = scanner.nextLine();
        while (!readLine.equals("over")) {
            System.out.println("客户端：" + readLine);
            dataOutputStream.writeUTF(readLine);
            dataOutputStream.flush();
            System.out.println("wait server message");
            String serverMsg = dataInputStream.readUTF();
            System.out.println("服务器：" + serverMsg);
            System.out.println("wait client in");
            readLine = scanner.nextLine();
        }

        dataOutputStream.close();
        dataInputStream.close();
        socket.close();
    }
}
